package com.java.socket;

import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Date;

public class TcpServerA {
	public static void main(String[] args) {
		ServerSocket ss=null;
		Socket s=null;
		PrintWriter pw=null;
		try {
			ss=new ServerSocket(8888);
			int i=1;
			while (true) {
				s = ss.accept();
				System.out.println(i+":"+s.getInetAddress());
				pw = new PrintWriter(new OutputStreamWriter(s.getOutputStream()));
				pw.println(new Date());
				pw.flush();
				i++;
			}			
		} catch (IOException e) {
			e.printStackTrace();
		} finally{
			if(s!=null) try{s.close();} catch(IOException e){}
			if(ss!=null) try{s.close();} catch(IOException e){}
		}
	}
}
